package com.arsn.myf.resource.config;

import com.arsn.myf.resource.entity.Oss;
import com.arsn.myf.resource.service.OssService;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * minio 连接配置
 * @author zhongrj
 * @since 2022-10-11
 */
@Configuration
public class MinioConfiguration {

    public static String endpoint;
    public static String accessKey;
    public static String secretKey;
    public static String bucketName;


        @Autowired
        private OssService ossService;


        @Bean
        public MinioClient minioClient(){
            //查询默认的oos源配置
            Oss oss= ossService.getDefaultOssInfo();
            //设置
            endpoint = oss.getEndpoint();
            accessKey = oss.getAccessKey();
            secretKey = oss.getSecretKey();
            bucketName = oss.getBucketName();
            //获取client 对象
            MinioClient client =MinioClient.builder()
                    .endpoint(oss.getEndpoint())
                    .credentials(oss.getAccessKey(), oss.getSecretKey())
                    .build();
            //返回
            return client;
        }

}
